package com.ysqcould.web.controller.content;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.content.domain.PressReproduce;
import com.ysqcould.content.domain.vo.PressReproduceVo;
import com.ysqcould.content.service.IPressReproduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文章转载记录Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/content/reproduce")
public class PressReproduceController extends BaseController
{
    @Autowired
    private IPressReproduceService pressReproduceService;

    /**
     * 查询文章转载记录列表
     */
    @PreAuthorize("@ss.hasPermi('content:reproduce:list')")
    @GetMapping("/list")
    public TableDataInfo list(PressReproduce pressReproduce)
    {
        startPage();
        List<PressReproduceVo> list = pressReproduceService.selectPressReproduceList(pressReproduce);
        return getDataTable(list);
    }

    /**
     * 导出文章转载记录列表
     */
    @PreAuthorize("@ss.hasPermi('content:reproduce:export')")
    @Log(title = "文章转载记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PressReproduce pressReproduce)
    {
        List<PressReproduceVo> list = pressReproduceService.selectPressReproduceList(pressReproduce);
        ExcelUtil<PressReproduceVo> util = new ExcelUtil<PressReproduceVo>(PressReproduceVo.class);
        util.exportExcel(response, list, "文章转载记录数据");
    }

    /**
     * 获取文章转载记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('content:reproduce:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pressReproduceService.selectPressReproduceById(id));
    }

    /**
     * 新增文章转载记录
     */
    @PreAuthorize("@ss.hasPermi('content:reproduce:add')")
    @Log(title = "文章转载记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PressReproduce pressReproduce)
    {
        pressReproduce.setAsId(getUserId());
        return toAjax(pressReproduceService.insertPressReproduce(pressReproduce));
    }

    /**
     * 修改文章转载记录
     */
    @PreAuthorize("@ss.hasPermi('content:reproduce:edit')")
    @Log(title = "文章转载记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PressReproduce pressReproduce)
    {
        return toAjax(pressReproduceService.updatePressReproduce(pressReproduce));
    }

    /**
     * 删除文章转载记录
     */
    @PreAuthorize("@ss.hasPermi('content:reproduce:remove')")
    @Log(title = "文章转载记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pressReproduceService.deletePressReproduceByIds(ids));
    }
}
